package com.itheima.service.impl;

import com.itheima.mapper.StuMapper;
import com.itheima.pojo.ClazzOption;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.StuQueryParam;
import com.itheima.pojo.Student;
import com.itheima.service.StuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class StuServiceImpl implements StuService {
    @Autowired
    StuMapper stuMapper;
    @Override
    public PageResult listByPage(StuQueryParam stuQueryParam) {
//         PageHelper.startPage(stuQueryParam.getPage(),stuQueryParam.getPageSize());
//        Page<Student> pages =(Page<Student>) stuMapper.list(stuQueryParam);
//        long total = pages.getTotal();
//        List<Student> result = pages.getResult();
////        new PageResult(total,result);
        return null;
    }

    @Override
    public void saveStu(Student student) {
        student.setCreateTime(LocalDateTime.now());
        student.setUpdateTime(LocalDateTime.now());
        stuMapper.saveStu(student);
    }

    @Override
    public Student findById(Integer id) {
        Student student =stuMapper.findById(id);
        return student;
    }

    @Override
    public void updateStu(Student student) {
        student.setUpdateTime(LocalDateTime.now());
        stuMapper.updateStu(student);
    }

    @Override
    public void delByIds(List<Integer> ids) {
        stuMapper.delByIds(ids);
    }

    @Override
    public void updateViolation(Integer id, Integer score) {
        stuMapper.updateViolation(id,score);
    }

    @Override
    public List<Map> getDegree() {
        List<Map> mapList =stuMapper.getDegree();
        return mapList;
    }

    @Override
    public ClazzOption getStuCount() {
        List<Map> mapList = stuMapper.getStuCount();
        List clazzList =new ArrayList<>();
        List dataList = new ArrayList<>();
        for (Map map : mapList) {
            clazzList.add(map.get("clazzList"));
            dataList.add(map.get("dataList"));
        }


        return new ClazzOption(clazzList,dataList);
    }
}
